<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Testimonial extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('Testimonial_model');
		$this->load->model('Produk_model');
		$this->load->library('session');
		$this->load->helper('url');
		$this->load->helper('bantuan_helper');
	}

	function index()
	{
		$this->load->library('pagination');
		$offset = $this->uri->segment(3);
		$config['base_url'] = site_url().'/testimonial/index';
		$config['total_rows'] = count($this->Testimonial_model->getTestimonial(FALSE,FALSE,FALSE,FALSE));
		$config['per_page'] = 2;
		$config['uri_segment'] = 3;
		$config['next_link'] = '&raquo;';
		$config['prev_link'] = '&laquo;';
		$config['anchor_class'] = "class = 'white_back'";  
		
		$data['ses_id'] = $this->session->userdata('session_id');
		$data['title'] = 'Testimonial';
		$data['arr_testi'] = $this->Testimonial_model->getTestimonial('enable',FALSE,$config['per_page'],$offset);
		
		
		$data['cumb'] = anchor('home','<strong>Home</strong>').' &raquo; Testimonial';
		$data['page'] = 'common'; // ONE RULE TO SHOW THE SIDEBAR
		
		$this->pagination->initialize($config);
		$data['main_view'] = 'slak/testimonial/index';
		$this->load->view('/slak/index',$data);
	}
	
	function add()
	{
		$this->form_validation->set_rules('isi_testi', 'Testimonial', 'required');
		
		if ($this->form_validation->run() == FALSE):
			$this->session->set_flashdata('message_testi_fail','Please write your testimonial first!');
			
			$data['alert_msg'] = "Related records has been added into Admin group.";
			redirect('home',$data);
		else:
		
			$date = date("Y-m-d h:i:s");
			$isi_testi = $this->input->post('isi_testi');
			$data = array('member_id' => $this->session->userdata('member_id'),
						'isi_testi' => $isi_testi,
						'date_added' => $date,
						'status' => '1'
						);  
			$this->Testimonial_model->addTestimonial($data);
			$this->session->set_flashdata('message_testi_ok','Thanks for your participation');
			redirect('home');

		endif;
	}
	
	function view()
	{
		
	}

}